package com.tanhua.server.controller;

import com.tanhua.server.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessageService messageService;



    @GetMapping(value = "/contacts",name = "当前登录人的好友")
    public ResponseEntity contactsList(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10")  Integer pagesize,
                                       String keyword
    ){

        return messageService.contactsList(page,pagesize,keyword);
    }

//    1号用户同意139号用户的加好友请求

    @PostMapping(value = "/contacts",name = "同意加好友请求")
    public ResponseEntity saveContacts(@RequestBody Map map){
        Long friendId = Long.parseLong (map.get("userId").toString());
        return messageService.saveContacts(friendId);
    }

    @GetMapping(value = "/likes",name = "当前登录人收到的点赞")
    public ResponseEntity queryLikes( @RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10")  Integer pagesize){
        return messageService.queryComment(1,page,pagesize);
    }

    @GetMapping(value = "/comments",name = "当前登录人收到的评论")
    public ResponseEntity queryComments( @RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10")  Integer pagesize){
        return messageService.queryComment(2,page,pagesize);
    }

    @GetMapping(value = "/loves",name = "当前登录人收到的点赞")
    public ResponseEntity queryLoves( @RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10")  Integer pagesize){
        return messageService.queryComment(3,page,pagesize);
    }

}
